<template>
	<view class="_company_item">
		<view class="u-p-l-32 u-p-r-32 ">
      <view class="topFlex">
        <view class="f-s-16 f-w-b u-line-1">{{data.name}}
          </view>
        <view class="peo">{{data.userCount}} 人 </view>
      </view>

			<view class="u-flex u-flex-items-center u-m-t-12">

				<status :bgColor="data.isAuth==1? 'rgba(22,119,255,0.1)':'rgba(255,22,30,0.1)'" :color="data.isAuth==1?'#1677FF':'#fc0d4d'" :text="data.isAuth==1? '经发已认证':'经发未认证'"></status>
				<status class="u-m-l-12" :bgColor="data.isPoliceAuth==1? 'rgba(22,119,255,0.1)':'rgba(255,22,30,0.1)'" :color="data.isPoliceAuth==1?'#1677FF':'#fc0d4d'" :text="data.isPoliceAuth==1?'公安已认证':'公安未认证'"></status>
			</view>

			<view class="u-m-t-24 f-s-14 u-flex u-flex-self-start">
				<view class="_title u-tips-color">所在位置</view>
				<view>{{data.floor.indexOf('层')>-1?data.floor:data.floor+'层' }}  {{data.room}}</view>
			</view>
			<view class="u-m-t-24 f-s-14 u-flex">
				<view class="_title u-tips-color">负责人</view>
				<view>{{data.legal}}</view>
			</view>
			<view class="u-m-t-24 f-s-14 u-flex">
				<view class="_title u-tips-color">联系方式</view>
<!--				<view>{{ data.urgentContactTel }}</view>-->


<!--        <view v-if="loadStatus==0">{{data.urgentContactTelDesensitize}}</view>-->
        <view >{{data.urgentContactTel}}</view>
<!--        <view v-if="userInfo.newRoleName=='警务室处置人员'||userInfo.newRoleName=='警务室负责人'" style="    color: #1677FF;font-size: 28rpx;margin-left: 50rpx;" class="btnOpen"-->
<!--              @click = "openClick">{{loadStatus==0?'显示':'隐藏' }}</view>-->





			</view>

			<view class="u-m-t-24 f-s-14 u-flex">
				<view class="_title u-tips-color">注册时间</view>
				<view>{{data.addTime}}</view>
			</view>
		</view>
		<up-line margin="24rpx 0 "></up-line>
		<view class="u-flex u-flex-end u-flex-items-center u-p-l-32 u-p-r-32" style="flex-wrap: wrap;height: 140rpx;">

      <view class="u-m-r-12" v-if="data.isAuth==0 && (userInfo.entName=='环创中心警务室'||userInfo.userEnterprises=='物业')">
        <up-button text="经发认证" :customStyle="{
					width: '146rpx',
					height: '56rpx',
					border: '1rpx solid #E5E5E5',
					background: '#fff',
					borderRadius: '8rpx',
					fontSize: '28rpx',
					color: 'color: rgba(0,0,0,0.65)'
				}" @click="jingfa"></up-button>
      </view>

      <view class="u-m-r-12" v-if="data.isPoliceAuth==0 && (userInfo.entName=='环创中心警务室'||userInfo.userEnterprises=='物业')">
        <up-button text="公安认证" :customStyle="{
					width: '146rpx',
					height: '56rpx',
					border: '1rpx solid #E5E5E5',
					background: '#fff',
					borderRadius: '8rpx',
					fontSize: '28rpx',
					color: 'color: rgba(0,0,0,0.65)'
				}" @click="gongan"></up-button>
      </view>

			<view class="u-m-r-12">
				<up-button text="单位详情" :customStyle="{
					width: '146rpx',
					height: '56rpx',
					border: '1rpx solid #E5E5E5',
					background: '#fff',
					borderRadius: '8rpx',
					fontSize: '28rpx',
					color: 'color: rgba(0,0,0,0.65)'
				}" @click="toCompanyInfo"></up-button>
			</view>


      <view class="u-m-r-12" v-if="data.isPoliceAuth==1 && (userInfo.entName=='环创中心警务室'||userInfo.userEnterprises=='物业')">
        <up-button text="取消认证" :customStyle="{
					width: '146rpx',
					height: '56rpx',
					border: '1rpx solid #E5E5E5',
					background: '#fa4b4b',
					borderRadius: '8rpx',
					fontSize: '28rpx',
					color: 'rgba(255,255,255,1)'
				}" @click="delate(data)"></up-button>
      </view>





      <view class="u-m-r-12">
        <up-button text="编辑企业" :customStyle="{
					width: '146rpx',
					height: '56rpx',
					border: '1rpx solid #E5E5E5',
					background: '#fff',
					borderRadius: '8rpx',
					fontSize: '28rpx',
					color: 'color: rgba(0,0,0,0.65)'
				}" @click="editor(data)"></up-button>
      </view>




			<view class="u-m-r-12">
				<up-button text="人员管理" :customStyle="{
					width: '146rpx',
					height: '56rpx',
					background: '#1677FF',
					borderRadius: '8rpx',
					fontSize: '28rpx',
					color: '#FFFFFF'
				}" @click="toPeople"></up-button>
			</view>
		</view>
	</view>
</template>

<script setup>

	import Status from '@/components/common/Status.vue'
  import {showConfirm} from "../utils/common";
  import {delCompanyInfo, updateCompanyData} from "../api/company";
  import storage from "../utils/storage";
  import {
    defineEmits, ref
  } from 'vue';
  import {toast} from "uview-plus";
	const props = defineProps({
		data: Object,
	})

  const emit = defineEmits(['refresh']);
	const toCompanyInfo = () => {
		uni.navigateTo({
			url: '/subPackages/company/info?id=' + props.data.id + '&name=' + props.data.name,
		})
	}
	const toPeople = () => {
		uni.navigateTo({
			url: '/subPackages/company/user_list?entID=' + props.data.id + '&name=' + props.data.name,
		})
	}
  const userInfo = storage.get('user_info');
  console.log('userInfo',userInfo)
  const loadStatus = ref(0)
  const openClick = ()=>{
    loadStatus.value===0?loadStatus.value=1:loadStatus.value=0
  }

  const jingfa = ()=>{

    showConfirm(`确定对企业【${props.data.name}】进行经发认证？`).then(res => {
      if (!res.confirm) return;
      updateCompanyData({id:props.data.id,authUserID:userInfo.userId, isAuth:1,areaID:props.data.areaID}).then(res=>{
        toast("认证成功")
        emit('refresh', true)
        // uni.$u.sleep(300).then(() => {
        //   uni.navigateBack(-1)
        // })
      })
    })
  }

  // 删除企业

  const delate = (e)=>{

    showConfirm(`确定取消企业【${e.name}】的公安认证吗？`).then(res => {
      if (!res.confirm) return;
      updateCompanyData({id:props.data.id,policeAuthUserID:userInfo.userId, isPoliceAuth:0,areaID:props.data.areaID}).then(res=>{
        toast("取消公安认证成功")
        emit('refresh', true)
        // uni.$u.sleep(300).then(() => {
        //   uni.navigateBack(-1)
        // })
      })
    })




  }



  const editor = (e)=>{

    uni.navigateTo({
      url: '/subPackages/company/post?isEditor=1&id='+e.id
    })

  }


  const gongan = ()=>{
    showConfirm(`确定对企业【${props.data.name}】进行公安认证？`).then(res => {
      if (!res.confirm) return;
      updateCompanyData({id:props.data.id,policeAuthUserID:userInfo.userId, isPoliceAuth:1,areaID:props.data.areaID}).then(res=>{
        toast("认证成功")
        emit('refresh', true)
        // uni.$u.sleep(300).then(() => {
        //   uni.navigateBack(-1)
        // })
      })
    })
  }
</script>

<style lang="scss" scoped>
	._company_item {
		background: #FFFFFF;
		box-shadow: 0rpx 2rpx 20rpx 0rpx rgba(0, 0, 0, 0.05);
		border-radius: 16rpx;
		padding: 32rpx 0;
		margin-bottom: 24rpx;

		._title {
			min-width: 144rpx;
			width: 144rpx;
		}

	}

  .topFlex{
    display: flex;
    justify-content: space-between;
    .peo{
      padding: 4rpx 15rpx;
      font-size: 28rpx;
      background-color: rgba(232, 232, 232, 0.4);
      border-radius: 5rpx;
      font-weight: bold;
      color: #505050;
      //color: #7f7f7f;
    }
  }
  .u-m-r-12{
    margin-right: 14rpx;
    //margin-top: 10rpx;
    //align-items: ;
    //flex-wrap: wrap;
    //width: 100%;
  }
</style>